<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<base href="<%=basePath%>">
<%@ include file="/base/jsp/include.jsp"%>
<script type="text/javascript">
    var grid;
    var addFun = function() {
        var dialog = parent.sy.modalDialog({
            title : '添加载体入驻公司',
            width : 800,
            height : 600,
            url : sy.contextPath + '/go.do?path=zaitiForCom/zaitiForComEdit',
            buttons : [ {
                text : '添加',
                handler : function() {
                    dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                }
            } ]
        });
    };
    var delFun = function() {
        var rows = grid.datagrid('getSelections');
        if (rows.length == 0) {
            parent.$.messager.w('请选择需要删除的记录！');
            return;
        }
        parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
            if (r) {
                var ids = [];
                for ( var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    ids.push(r.id);
                }
                var id = ids.join(',');
                
                $.post(sy.contextPath + '/companyRegisterNew/del.do', {
                    id : id
                }, function() {
                    rows.length = 0;//必须，否则有bug
                    grid.datagrid('reload');
                }, 'json');
            }
        });
    };
    
    var editFun = function() {
        var rows = grid.datagrid('getSelections');
        if (rows.length != 1) {
            parent.$.messager.w('请选择一条记录进行编辑！');
            return;
        }
        var dialog = parent.sy.modalDialog({
            title : '修改',
            width : 800,
            height : 600,
            url : sy.contextPath + '/go.do?path=zaitiForCom/zaitiForComEdit&id=' + rows[0].id,
            buttons : [ {
                text : '编辑',
                handler : function() {
                    dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                }
            } ]
        });
    };
    
    $(function() {
        
        var menu;
        menu={
                url : sy.contextPath + '/companyRegisterNew/list.do',
                toolbar : '#toolbar',
                singleSelect : false,
                columns : [ [ {
                    width : $(this).width() * 0.1,
                    title : '企业名称',
                    field : 'companyName',
                    align : 'center'
                },{
                    width : $(this).width() * 0.1,
                    title : '行业类别',
                    field : 'cyTypeName',
                    align : 'center'
                },{
                    width : $(this).width() * 0.1,
                    title : '使用面积(平方米)',
                    field : 'area',
                    align : 'center'
                },{
                    width : $(this).width() * 0.1,
                    title : '选择载体',
                    field : 'zaitiName',
                    align : 'center'
                }, {
                    width : $(this).width()*0.1,
                    title : '从业人员(人)',
                    field : 'pepole',
                    align : 'center',
                },{
                    width : $(this).width()*0.1,
                    title : '属地',
                    field : 'shudi',
                    align : 'center',
                }, {
                    width : $(this).width()*0.1,
                    title : '起始时间',
                    field : 'beginTime',
                    align : 'center',
                    formatter : function(value, row, index) {
                    	if(row.beginTime){
                    		return row.beginTime.substring(0,10);
                    	}
                        
                    }
                },{
                    width : $(this).width()*0.1,
                    title : '结束时间',
                    field : 'endTime',
                    align : 'center',
                    formatter : function(value, row, index) {
                    	if(row.endTime){
                    		return row.endTime.substring(0,10);
                    	}
                        
                    }
                }
                ] ]
            };
        
        grid = $('#grid').datagrid(menu);
    }); 
    
    $(function() {
        $('#zaiti').combobox({
            url:sy.contextPath + '/zaiti/myZaitilist.do',
            valueField:'id',
            textField:'zaitiName',
        });
    });
    
    function exportExcel(){
        var data = {id: 123}
        var url = sy.contextPath + '/companyRegisterNew/exportExcel.do';
        location.href = url;
    }
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
    <div id="toolbar" style="display: none;">
    
        <table>
            <tr>
                <td>
                    <table>
                        <tr>                
                            <td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_add',plain:true" onclick="addFun();">添加</a></td>
                            <td><div class="datagrid-btn-separator"></div></td>
                            <td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-table_edit',plain:true" onclick="editFun();">修改</a></td>
                            <td><div class="datagrid-btn-separator"></div></td>
                            <td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-table_delete',plain:true" onclick="delFun();">删除</a></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <form id="searchForm">
                        <table>
                            <tr>
                                <td>企业名称：</td>
                                <td>
                                    <input type="text" class="easyui-textbox" name="name" style="width: 150px"  />
                                </td>
                                <td>
                                    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',sy.serializeObject($('#searchForm')));">过滤</a>
                                    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
                                    <a href="javascript:void(0);" onclick="exportExcel();">导出Excel</a>
                                </td>
                            </tr>
                        </table>
                    </form>
                </td>
            </tr>
        </table>
    </div>
    <div data-options="region:'center',fit:true,border:false">
        <table id="grid" data-options="fit:true,border:false"></table>
    </div>
</body>
</html>